package com.gitee.liuzhi.demo.mapstruct;

import com.gitee.liuzhi.demo.mapstruct.converter.UserConverter;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.List;

/**
 * Created by 2022/4/21/0021
 *
 * @author LiuZhi
 * @version V1.0
 * @description: 对象转换工具 MapStruct
 * <p>
 * <a href="https://mapstruct.org/">MapStruct 对象转换工具</a>
 * MapStruct是一个代码生成器, 它极大地简化了基于约定优于配置方法的Java bean类型之间映射的实现
 * 与其他映射框架相比, MapStruct在编译时生成bean映射, 这确保了高性能
 */
public class MapStructMain {

    public static void main(String[] args) {
        User user = new User(1, "LiuZhi", LocalDateTime.now(), LocalDateTime.now());
        UserDTO userDTO = UserConverter.INSTANCE.toDTO(user);
        UserVO userVO = UserConverter.INSTANCE.toVO(user);
        System.out.println(userDTO);
        System.out.println(userVO);
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @Builder
    public static class User {
        private Integer id;
        private String name;
        private LocalDateTime createTime;
        private LocalDateTime updateTime;
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    @Builder
    public static class UserDTO {
        private List<Integer> id;
        private String name;
        private LocalDateTime createTime;
        private String updateTime;
    }

    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    @Builder
    public static class UserVO {
        private Integer id;
        private String name;
        private LocalDateTime createTime;
        private LocalDateTime updateTime;
    }


}
